/*
n k x
a[n]
k*a[n]
从后向前累加
*/
#include <cstdio> 
#include <cmath>
using namespace std;
template <typename T>
inline void read(T& x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}

inline void write(long long x)
{
    if(x>=10) write(x/10);
    putchar(x%10+'0');
}
#define DEBUG
using ll=long long;
const ll N=2e5+10;
ll n, k; ll x, sum;
ll a[N];

ll cnt;
void init()
{
    sum=0;
    read(n); read(k); read(x);
    for(int i=1; i<=n; i++) read(a[i]), sum+=a[i];
}


void solve()
{
    init();
    if(sum*k<x) {write(0), puts(""); return;} //无解

    ll circle=k-x/sum-1; //未使用几个整数组
    ll cur=x/sum*sum; //轮回数组和
    ll in=n; //数组内下标
    while(cur<x&&in) cur+=a[in--]; //in指向左边界的左元素
    in++; //指向左元素
    // ll ans=1ll*circle*n+1ll*in;
    write(1ll*circle*n+in); puts("");
}

#undef DEBUG
signed main()
{
    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        freopen("../out.txt", "w", stdout);
    #endif

    int T=1; scanf("%d", &T);
    while(T--) 
    {
        solve();
    }
    return 0;
}